package API.Map.HashMap.Practise.Hometown;

import java.util.HashMap;
import java.util.Map;

// HashMap中的key若为自定义对象，需要重写hashCode和equals方法
public class Hometown {
    public static void main(String[] args) {
        Map<Student, String> map = new HashMap<Student, String>();
        Student stu1 = new Student("Jack", 10);
        Student stu2 = new Student("John", 20);
        Student stu3 = new Student("Jane", 30);
        map.put(stu1, "England");
        map.put(stu2, "England");
        map.put(stu2, "England");
        map.put(stu3, "England");
        map.forEach((key, value) -> System.out.println(key + " : " + value));
    }
}
